package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.servlet;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.dao.VozacDao;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Vozac;

@SuppressWarnings("serial")
public class PrikazVozacaKontroler extends HttpServlet {

	@EJB
	private VozacDao cVozacDao;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		Collection<Vozac> vozaci = cVozacDao.pronadjiSve();

		for (Iterator<Vozac> it = vozaci.iterator(); it.hasNext();) {
			Vozac v = it.next();
			Double cena = cVozacDao.ukupnaCenaPruzenihUsluga(v.getId());
			v.setUkupnaCenaPruzenihUsluga(cena == null ? cena : 0.0);
		}

		req.setAttribute("vozaci", vozaci);
		getServletContext().getRequestDispatcher("/jsp/prikazVozaca.jsp")
				.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
